import 'package:shop/common/shop_material.dart';

class Page2 extends StatefulWidget {
  Page2({Key key}) : super(key: key);
  @override
  _Page2State createState() => _Page2State();
}

class _Page2State extends State<Page2> {
  int choseIndex = 0;
  //这里写属性
  @override
  void initState() {
//初始化
    super.initState();
    _initGetData();
  }

  _initGetData() async {
//网络请求
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: Center(child: Text("分类")),
        elevation: 0,
        actions: [
          Center(child: Icon(Icons.shop)),
        ],
      ),
      body: Container(
        color: Colors.white,
        child: Row(
          children: [
            Expanded(
              child: ListView.builder(
                itemCount: 10,
                itemBuilder: (BuildContext context, int index) {
                  return InkWell(
                    onTap: () {
                      setState(() {
                        choseIndex = index;
                      });
                    },
                    child: Container(
                      height: 80.h,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          color: choseIndex == index
                              ? Colors.white
                              : Colors.grey[50]),
                      child: Container(
                        decoration: BoxDecoration(
                          border: Border(
                              left: BorderSide(
                                  width: 5,
                                  color: choseIndex != index
                                      ? Colors.white
                                      : Colors.green)),
                        ),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: <Widget>[
                            Text("分类$index"),
                          ],
                        ),
                      ),
                    ),
                  );
                },
              ),
            ),
            Expanded(
              flex: 3,
              child: GridView.builder(
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 3,
                    childAspectRatio: 0.8,
                    mainAxisSpacing: 10,
                    crossAxisSpacing: 10,
                  ),
                  itemCount: 50,
                  itemBuilder: (context, index) {
                    return InkWell(
                      onTap: () {},
                      child: Container(
                        alignment: Alignment.center,
                        child: Text("数据$index"),
                      ),
                    );
                  }),
            ),
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
//销毁
    super.dispose();
  }
}
